package main

import (
	"fmt"
	//	"html/template"
	"io/ioutil"
	//	"io/ioutil"
	//	"log"
	"net/http"

	"github.com/whxmail/whx/types"
)

func login(w http.ResponseWriter, r *http.Request) {

	fmt.Println("method:", r.Method) //获取请求的方法
	/*
		t, _ := template.ParseFiles("usr/index.html")
		t.Execute(w, nil)
	*/
	//请求的是登陆数据，那么执行登陆的逻辑判断
	r.ParseForm()
	usr := types.User{Username: r.Form.Get("username"), Password: r.Form.Get("password")}
	fmt.Println(usr)
	w.Write([]byte("Hello ......."))

	data := types.Data{"REQUEST": "LOGIN", "USERNAM": usr.Username, "PASSWOR": usr.Password}
	resp, err := data.Post("http://127.0.0.1:9090/login")
	test(err)
	test(resp)
	test(resp.Body)

	buf, _ := ioutil.ReadAll(resp.Body)
	//dt := types.Json2Data(buf)
	//test(dt)
	w.Write(buf)

}
